<?php
if ($_REQUEST['additional']) {
    $_REQUEST['additional'] = str_replace('__price_', '', $_REQUEST['additional']);
    $innerif = explode(' ', str_replace('€', '', $CleanCode->Decode($_REQUEST['additional'])));
    $searchby = "price";
}

if ($_REQUEST['brand']) {
    $_REQUEST['brand'] = str_replace('__brand_', '', $_REQUEST['brand']);
    $innerif[0] = $CleanCode->Decode($_REQUEST['brand']);
    $searchby = "brand";
}

$Category = $CleanCode->Decode($_REQUEST['c']);
$mc = $CleanCode->Decode($_REQUEST['mc']);
$sc = $CleanCode->Decode($_REQUEST['sc']);
$additional = $CleanCode->Decode($_REQUEST['additional']);
$brand = $CleanCode->Decode($_REQUEST['brand']);

$ItemCount = $XMLInstance->GetStockCount($Category, $mc, $sc, $innerif);
if (isset($_REQUEST['pages'])) {
    $_SESSION['ItemAmount'] = $_REQUEST['pages'];
} elseif (!isset($_SESSION['ItemAmount'])) {
    $_SESSION['ItemAmount'] = 10;
}
if ($_REQUEST['showall'] == 1 or $_SESSION['ItemAmount'] == 1) {
    $_SESSION['ItemAmount'] = $ItemCount;
    $StartItem = 1;
    $EndItem = $_SESSION['ItemAmount'];
    $ShowAll = 1;
}
if (isset($_REQUEST['itemorder'])) {
    $_SESSION['itemOrder'] = $_REQUEST['itemorder'];
} elseif (!isset($_SESSION['itemOrder'])) {
    $_SESSION['itemOrder'] = "asort";
}
if (isset($_REQUEST['pagenum'])) {
    $PageNum = $_REQUEST['pagenum'];
} else {
    $PageNum = 1;
}
if ($PageNum == 1) {
    $StartItem = 1;
} else {
    $StartItem = (($PageNum * $_SESSION['ItemAmount']) + 1) - $_SESSION['ItemAmount'];
}
if ($ItemCount < $_SESSION['ItemAmount']) {
    $EndItem = $ItemCount;
} else {
    $EndItem = ($StartItem + $_SESSION['ItemAmount']) - 1;
}
if ($EndItem == 11 and $ItemCount != 11) {
    $EndItem = 10;
}
if ($EndItem > $ItemCount) {
    $EndItem = $ItemCount;
}
$PageCount = ceil($ItemCount / $_SESSION['ItemAmount']);
$FormAction = $loc . "search/" . $_REQUEST['c'] . "/";
if ($mc != '') {
    $FormAction .= $_REQUEST['mc'] . "/";
}
if ($sc != '') {
    $FormAction .= $_REQUEST['sc'] . "/";
}

//set the main header image
switch ($_REQUEST['c']) {
//    case 'handy-zubeh-oe-r': $BannerImg = "cb_940x100_category_iphone3gcharger_v1.jpg";
//        $BannerLink = "/mobiles/mains-chargers/apple-mains-chargers/";
//        $BannerDesc = "";
//        break;
//    case 'electronics': $BannerImg = "cb_940x100_category_compaqpresario_v5.jpg";
//        $BannerLink = "/moreinfo/5052271028622/electronics/";
//        $BannerDesc = "";
//        break;
    default: $BannerImg = "";
        $BannerLink = "#";
        $BannerDesc = "";
        break;
}
?>
<form method="post" action="<?php echo $FormAction; ?>" name="searchsettings" id="searchsettings">
    <input type="hidden" name="c" value="<?php echo $_REQUEST['c']; ?>" />
    <input type="hidden" name="mc" value="<?php echo $_REQUEST['mc']; ?>" />
    <input type="hidden" name="sc" value="<?php echo $_REQUEST['sc']; ?>" />
    <input type="hidden" name="showall" id="showall" value="<?php echo $ShowAll; ?>" />
    <input type="hidden" name="pagenum" id="pagenum" value="<?php echo $PageNum; ?>" />
    <input type="hidden" name="itemorder" id="itemorder" value="<?php echo $_SESSION['itemOrder']; ?>" />
    <input type="hidden" name="additional" id="additional" value="<?php echo $_REQUEST['additional']; ?>" />
    <input type="hidden" name="brand" id="brand" value="<?php echo $_REQUEST['brand']; ?>" />
    <div>
        <div id="searchbanner"<?php // if($BannerClass != "") echo " class=\"banner-". $BannerClass ."\""; ?>>
                <?php if ($BannerImg) {
                    echo "<a href=\"$BannerLink\" title=\"$BannerDesc\"><img src=\"" . $loc . "/images/banners/$BannerImg\" alt=\"$BannerDesc\" /></a>";
                } ?>
        </div>
        <div id="searchtopcontainer">
            <div id="searchtopinnercontainer">
                <div id="searchtopinnercontainer2">
                    <div id="searchtopitemcount">
                        <b>Wir haben <?php echo $ItemCount; ?> Artikel für Sie!</b>
                    </div>
                    <div id="searchtopitemshowall">
		                Ansicht <b><?php echo $StartItem; ?> - <?php echo $EndItem; ?></b> von <b><?php echo $ItemCount; ?></b> | 
                        <a href="javascript:document.getElementById('showall').value=1;document.searchsettings.submit();">Alles anzeigen</a>
                    </div>
                    <div id="searchtopshowoptions">
                        <select name="pages" onchange="javascript:document.getElementById('showall').value=0;document.getElementById('pagenum').value=1;submit();">
<?php
                for ($o = 10; $o <= 50; $o+=10) {
                    if ($o == $_SESSION['ItemAmount']) {
                        $iamselected = true;
                        $Selected = "Selected";
                        $o == 50;
                    } else {
                        $Selected = "";
                    }
                    echo "<option value=\"" . $o . "\" " . $Selected . ">" . $o . " Produkte pro Seite</option>";
                }
?>
                                        <option value="1" <?php if (!$iamselected) {
                    echo "Selected";
                } ?>>Alles anzeigen</option>
                                    </select>
                                    <select name="itemorder" onchange="submit();">
                                        <option value='asort' <?php if ($_SESSION['itemOrder'] == asort) {
                    echo "Selected";
                } ?>>Preis: niedrigster zuerst</option>
                                        <option value='arsort' <?php if ($_SESSION['itemOrder'] == arsort) {
                    echo "Selected";
                } ?>>Preis: h&ouml;chster zuerst</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="searchbreadcrumbpaging">
                        <div id="breadcrumb">
<?php

                echo "<a href=\"" . $loc . "\"><b>Home</b></a> | <a href=\"" . $loc . "search/" . $_REQUEST['c'] . "/\"><b>" . ucwords($Category) . "</b></a>";
                if ($mc != '') {
                    echo " | <a href=\"" . $loc . "search/" . $_REQUEST['c'] . "/" . $_REQUEST['mc'] . "/\">" . ucwords($mc) . "</a>";
                }
                if ($sc != '') {
                    echo " | <a href=\"" . $loc . "search/" . $_REQUEST['c'] . "/" . $_REQUEST['mc'] . "/" . $_REQUEST['sc'] . "/\">" . ucwords($sc) . "</a>";
                }
                if ($additional != '') {
                    //echo " | <a href=\"" . $loc . "search/" . $_REQUEST['c'] . "/" . $_REQUEST['mc'] . "/" . $_REQUEST['sc'] . "/" . $_REQUEST['additional'] . "/\">" . ucwords($additional) . "</a>";
                    echo " | <span style='color:#2982D9;font-size:11px;font-weight:bold;'>" . $additional . "</span>";
                }
                if ($brand != '') {
                    //echo " | <a href=\"" . $loc . "search/" . $_REQUEST['c'] . "/" . $_REQUEST['mc'] . "/" . $_REQUEST['sc'] . "/" . $_REQUEST['brand'] . "/\">" . ucwords($brand) . "</a>";
                    echo " | <span style='color:#2982D9;font-size:11px;font-weight:bold;'>" . ucwords($brand) . "</span>";
                }
?>
                        </div>
                        <div id="pagenumbers">
<?php
                for ($i = 1; $i <= $PageCount; $i++) {
                    if (($PageNum > 4 and $i == 2)) {
                        if ($PageNum > $PageCount - 3 and $norepeatelispe != 1) {
                            $i = $PageNum - (($PageCount - $PageNum - 5) * -1);
                            $norepeatelispe = 1;
                        } else {
                            $i = $PageNum - 2;
                        } echo "<div class='elispe'>...</div>";
                    }
                    if ($PageCount > 7 and $i == $PageNum + 3 and $PageNum + 3 > 7) {
                        $i = $PageCount;
                        echo "<div class='elispe'>...</div>";
                    }
                    if ($PageCount > 7 and $i == 7 and $PageNum < 5) {
                        $i = $PageCount;
                        echo "<div class='elispe'>...</div>";
                    }
                    echo "<a href=\"javascript:document.getElementById('pagenum').value=" . $i . ";document.searchsettings.submit();\">";
                    echo "<div class='";
                    if ($PageNum == $i) {
                        echo "activepage";
                    } else {
                        echo "inactivepage";
                    }
                    echo "'>" . $i . "</div></a>";
                }
?>
                        </div>
                    </div>
                </div>
            </form>
            <div style="float:left; clear:both; border-top:2px solid #002B6B; width:940px;"></div>
            <div style="float:left; display:block; width:100%; clear:both; height:10px;">&nbsp;</div>
            <div id="refineSearch">
<?php include('includes/searchOptions.inc.php'); ?>
            </div>
            <div id="search" style="opacity:1;">
<?php include('includes/productSearch.php'); ?>
            </div>
            <div style="float:left; clear:both; border-bottom:2px solid #002B6B; width:940px;"></div>
            <div id="pagenumbers" style="padding-top:8px;">
<?php
                for ($i = 1; $i <= $PageCount; $i++) {
                    if (($PageNum > 4 and $i == 2)) {
                        if ($PageNum > $PageCount - 3 and $norepeatelispe != 1) {
                            $i = $PageNum - (($PageCount - $PageNum - 5) * -1);
                            $norepeatelispe = 1;
                        } else {
                            $i = $PageNum - 2;
                        } echo "<div class='elispe'>...</div>";
                    }
                    if ($PageCount > 7 and $i == $PageNum + 3 and $PageNum + 3 > 7) {
                        $i = $PageCount;
                        echo "<div class='elispe'>...</div>";
                    }
                    if ($PageCount > 7 and $i == 7 and $PageNum < 5) {
                        $i = $PageCount;
                        echo "<div class='elispe'>...</div>";
                    }
                    echo "<a href=\"javascript:document.getElementById('pagenum').value=" . $i . ";document.searchsettings.submit();\">";
                    echo "<div class='";
                    if ($PageNum == $i) {
                        echo "activepage";
                    } else {
                        echo "inactivepage";
                    }
                    echo "'>" . $i . "</div></a>";
                }
?>
</div>
<div style="float:left; display:block; width:100%; clear:both; height:10px;">&nbsp;</div>